﻿@using DotNet.Edu.Service
@model ExcerciseQuestion
@{
    Layout = null;
    int index = ViewBag.index;
    int prveIndex = index - 1;
    int nextIndex = index + 1;
    List<ExcerciseQuestion> examQuestions = ViewBag.examQuestions;
    StudentSession studentSession = ViewBag.studentSession;
}
@if (Model == null)
{
    <div class="bs-callout bs-callout-warning" style="margin-right: 15px; margin-left: 15px;">
        <h4>暂无考题</h4>
    </div>
}
else
{
    <div class="row" style="margin-top: 15px; margin-left: 15px;margin-right: 15px; border: 1px solid #cac8c9; padding: 15px;">
        <div class="col-md-4" style="padding-left: 0">
            <div style="height: 32px; line-height: 32px; color: #ff0000; font-size: 20px;">
                @if (studentSession.IsExamCommit)
                {
                    <text>考试时长：</text><span>90:00</span>
                }
                else
                {
                    <input id="noCommit" type="hidden"/>
                    <text>剩余时间：</text><span id="remainingTime">00:00</span>
                }
            </div>
        </div>
        <div class="col-md-8 text-right" style="padding-right: 0">
            @if (prveIndex > -1)
            {
                <a class="btn btn-default navQuestion" data-url="@Url.Action("_Question", new {index = prveIndex})" style="margin-left: 10px;">
                    <span class="fa fa-arrow-left"></span> 上一题
                </a>
            }

            @if (nextIndex < examQuestions.Count)
            {
                <a class="btn btn-default navQuestion" id="nextQuest" data-url="@Url.Action("_Question", new {index = nextIndex})" style="margin-left: 10px;">
                    <span class="fa fa-arrow-right"></span> 下一题
                </a>
            }
            @if (!studentSession.IsExamCommit)
            {
                <a class="btn btn-default" id="pause_quest" style="margin-left: 10px;">
                    <span class="fa fa-pause"></span> 暂停
                </a>
                <a class="btn btn-default" id="commit_quest" data-url="@Url.Action("Commit")" style="margin-left: 10px;">
                    <span class="fa fa-arrow-up"></span> 交卷
                </a>
            }
        </div>
    </div>


    <div class="row" style="margin-top: 15px; margin-left: 15px; margin-right: 15px; border: 1px solid #cac8c9; padding: 10px;">
        @for (int i = 0; i < examQuestions.Count; i++)
        {
            var quest = examQuestions[i];
            var current = i + 1;
            if (!studentSession.IsExamCommit)
            {
                <div class="exam_question_num @Html.WriteValue(quest.UserSelected.HasValue, "bgcolor-info") @Html.WriteValue(index==i, "bgcolor-warning")" data-value="@current" data-url="@Url.Action("_Question", new {index = i})">@current</div>
            }
            else
            {
                <div class="exam_question_num @Html.WriteValue(quest.UserSelected.HasValue && quest.UserResult,"bgcolor-success") @Html.WriteValue(quest.UserSelected.HasValue && !quest.UserResult,"bgcolor-danger") @Html.WriteValue(index==i, "bgcolor-warning")" data-value="@current" data-url="@Url.Action("_Question", new {index = i})">@current</div>
            }
        }
    </div>

    <div class="row" id="exercise_row" style="margin-top: 15px; margin-left: 15px; margin-right: 15px; border: 1px solid #cac8c9; padding: 20px;">
        <p class="exercise_title">@(index + 1)、@Model.Name</p>
        <div>
            <ul class="exercise_answer">
                @if (Model.QuestType == "1") //判断
                {
                @Html.Partial("../SimulatorExercise/_pd", Model)
                }
                else if (Model.QuestType == "2") //单选
                {
                @Html.Partial("../SimulatorExercise/_sx", Model)
                }
                else if (Model.QuestType == "3"|| Model.QuestType == "4") //多选
                {
                @Html.Partial("../SimulatorExercise/_mx", Model)
                }
            </ul>
        </div>
        <div class="row" style="margin-top: 15px;">
            <div class="col-md-6">
                @if (studentSession.IsExamCommit)
                {
                    <div id="quest_result">
                        您选择的答案：<span id="user_result" class="user_result">@Model.UserAnswer</span>
                        @if (Model.UserResult)
                        {
                            <a class="btn btn-success exercise_btn" id="answer_yes" style="width: 120px;">回答正确</a>
                        }
                        else
                        {
                            <a class="btn btn-danger exercise_btn" id="answer_no" style="width: 250px;">正确答案：@Model.Answer</a>
                        }
                    </div>
                }
                else
                {
                    <div class="@Html.WriteValue(!Model.UserSelected.HasValue, "fxhide")" id="quest_result" data-url="@Url.Action("CheckQuestion", new {questionId = Model.Id})">
                        您选择的答案：<span id="user_result" class="user_result">@Model.UserAnswer</span>
                    </div>
                }
            </div>
            <div class="col-md-6 text-right" style="padding-right: 15px;">
                @if (!studentSession.IsExamCommit)
                {
                    if (Model.A.IsNotEmpty())
                    {
                        <a class="btn btn-primary exercise_btn answer_btn" data-value="A">A</a>
                    }
                    if (Model.B.IsNotEmpty())
                    {
                        <a class="btn btn-primary exercise_btn answer_btn" data-value="B">B</a>
                    }
                    if (Model.C.IsNotEmpty())
                    {
                        <a class="btn btn-primary exercise_btn answer_btn" data-value="C">C</a>
                    }
                    if (Model.D.IsNotEmpty())
                    {
                        <a class="btn btn-primary exercise_btn answer_btn" data-value="D">D</a>
                    }
                    if (Model.E.IsNotEmpty())
                    {
                        <a class="btn btn-primary exercise_btn answer_btn" data-value="E">E</a>
                    }
                    if (Model.QuestType == "3"|| Model.QuestType == "4")
                    {
                        <a class="btn btn-primary exercise_btn answer_submit_btn" style="width:65px">提交</a>
                    }
                }
            </div>
        </div>
    </div>

    <input id="currentQuestionUrl" type="hidden" data-url="@Url.Action("_Question", new {index})" />
    <input id="correctAnswer" type="hidden" value="@Model.Answer" />
}
